#ifndef __LOG_BASE_H__
#define __LOG_BASE_H__

#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>

class CLogBase
{
public:
	CLogBase();
	~CLogBase();
public:
	int Initialize(
		const char* pszLogBaseName, 
		long lShiftType = 0, 
		long lMaxLogNum = 30, 
		long lMax = 10000000);

	int Log(int iLogFormat, const char *sFormat, va_list ap);

private:
	typedef struct 
	{
		FILE	*pLogFile;
		char	sBaseFileName[80];
		char	sLogFileName[80];
		int	    iShiftType;		// 0 -> shift by size,  1 -> shift by LogCount, 2 -> shift by interval, 3 ->shift by day, 4 -> shift by hour, 5 -> shift by min
		int	    iMaxLogNum;
		long	lMaxSize;
		long	lMaxCount;
		long	lLogCount;
		time_t	lLastShiftTime;
		pid_t   lPid;
	} LogFile;

private:
	int ShiftFiles();
	std::string GetDateTimeStr(time_t *mytime);
	std::string GetCurDateTimeStr();
	
	LogFile m_stLogFile;
	bool m_bInit;
};

#endif /* LOG_BASE_H */


